package com.focusai.efairy.model.request;

import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.model.msg.MsgItem;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.PureJSONRequest;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by luo_guangwen on 2017/8/12.
 */

public class DevCmdControlRequest extends PureJSONRequest<MsgItem> {
    private long deviceId;   //设备编号
    private int control_order;               //控制指令，66-查询ccid，128-复位，129-消音

    public DevCmdControlRequest(long deviceId, int control_order, Response.Listener<MsgItem> listener) {
        super(UrlUtils.createUrl("/appapi/device_control"), listener);
        this.deviceId = deviceId;
        this.control_order = control_order;
    }

    @Override
    protected MsgItem parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<MsgItem>() {
        }.getType());
    }

    @Override
    public String getPureJSON() throws JSONException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("efairyuser_id", CacheManager.getUserId());
        jsonObject.put("access_token", CacheManager.getAccessToken());
        jsonObject.put("efairydevice_id", deviceId);
        jsonObject.put("control_order", control_order);
        return jsonObject.toString();
    }
}
